package com.classes.attributes;

import java.nio.ByteBuffer;

import com.classes.attributes.logic.Attribute;
import com.classes.attributes.logic.Attribute_code;
import com.classes.attributes.logic.Attribute_lineNumberTable;
import com.classes.attributes.logic.Attribute_sourceFile;
import com.classes.attributes.logic.Attribute_stackmaptable;
import com.classes.constants.logic.Constants;

public class AttributeFactory {


    protected static Attribute create(ByteBuffer buffer) {
        short name_index = buffer.getShort();
        String nameIdex = Constants.contants_pool.get(name_index - 1).getContent();
        Attribute attribute = null;
        int length = buffer.getInt();

        System.out.println("Attribute_nameIdex==========" + nameIdex);
        switch (nameIdex) {
            case "Code": {
                attribute = new Attribute_code(name_index, length);
                break;
            }

            case "LineNumberTable": {
                attribute = new Attribute_lineNumberTable(name_index, length);
                break;
            }

            case "SourceFile": {
                attribute = new Attribute_sourceFile(name_index, length);
                break;
            }
            case "StackMapTable": {
                attribute = new Attribute_stackmaptable(name_index, length);
                break;
            }

        }

        return attribute;

    }

    public static void main(String[] args) {
        int a = 0xb100;
        System.out.println(Integer.toUnsignedString(a));
    }
}
